/*
 * Update controller.java
 *
 * Created on February 13, 2007
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

/**
 *
 * @author craig marshall
 */
package finalintex2web;
import java.util.*;
import java.io.*;
import java.sql.*;
/**
 * Version 1.0
 *
 * A class used to centralize the saving of transaction and payment info
 */
public class UpdateController {
    
    
    
    
    ///////////////////////////////////////
    ///   Singleton pattern
    
    private static UpdateController instance = null;
    
    /** Creates a new instance of UpdateControlerDAO */
    private UpdateController() {
    }
    
    /**
     * 
     * @return 
     */
    public static synchronized UpdateController getInstance() {
        if (instance == null) {
            instance = new UpdateController();
        }
        return instance;
    }
/**
     *  saves the transaction, transaction lines, and payments
     *  @param trans is the transaction
     *  @param  pay is the payment
     */
public void PostSale(TransactionBO trans, PaymentBO pay){
    try{
    ArrayList<TransactionLineBO> translines = new ArrayList<TransactionLineBO>();
    TransactionDAO.getInstance().save(trans);   
    PaymentDAO.getInstance().save(pay); 
    translines = trans.getTransactionlines();
    for(int x =0; x< translines.size();x++){
        TransactionLineDAO.getInstance().save(translines.get(x)); 
    }
    
    
         
    
    }
     catch(DataException e){e.printStackTrace();}
     catch(ConnectionPoolException e){e.printStackTrace();}
}
}